﻿Partial Public Class ResultsEntryForm

    Public Const UsageBackgroundEmpty As Integer = 16777215

    Public Enum ResultColor As Integer 'TODO read value from ResultFlags
        ValidEqual = 16564000
        GreaterThanTolerance = 16741680
        LowerThanTolerance = 16570000
        GreaterThanRejection = -65960
        LowerThanRejection = 16711935
        BooleanPass = 65280
        BooleanReject = 255
    End Enum


    Public Overridable Sub SampleDetail_MasterRowCellStyle(sender As Object, e As RowCellStyleEventArgs)
        Dim aView As GridView = DirectCast(sender, GridView)
        Dim aRow As System.Data.DataRow = aView.GetDataRow(e.RowHandle)

        'Solution pour le row surligne en bleu meme avec des merge cell
        If e.RowHandle = aView.FocusedRowHandle Then
            e.Appearance.Assign(aView.GetViewInfo().PaintAppearance.GetAppearance("FocusedRow"))
        End If

        If aRow IsNot Nothing Then
            SetResultBackcolorForecolor(aRow, e)
            SetComment(aRow, e)
        End If

    End Sub

    Public Overridable Sub SampleDetail_MasterRowStyle(ByVal sender As Object, ByVal e As RowStyleEventArgs)
        Dim aView As GridView = DirectCast(sender, GridView)
        Dim aRow As System.Data.DataRow = aView.GetDataRow(e.RowHandle)

        SetBackgroudColor(aRow, e)

    End Sub

    Public Overridable Sub SampleDetail_MasterRowClick(ByVal sender As Object, ByVal e As RowClickEventArgs)
        Dim aView As GridView = DirectCast(sender, GridView)
        Dim aRow As System.Data.DataRow = aView.GetDataRow(e.RowHandle)

        If aRow IsNot Nothing Then
            SetResultValidation(aRow, aView)
        End If
    End Sub

    ''' <summary>
    ''' This sub sets column Result backcolor and forecolor 
    ''' </summary>
    ''' <param name="aRow"></param>
    ''' <remarks></remarks>
    Public Overridable Sub SetResultBackcolorForecolor(ByVal aRow As DataRow, e As RowCellStyleEventArgs)
        If Not IsDBNull(aRow("RsltFlgColor")) Then
            Dim RsltFlgColor As Decimal = CType(aRow("RsltFlgColor"), Decimal)

            If e.RowHandle >= 0 Then
                If e.Column.FieldName = "Result" AndAlso Not IsDBNull(RsltFlgColor) AndAlso RsltFlgColor <> UsageBackgroundEmpty Then
                    e.Appearance.BackColor = ColorTranslator.FromOle(CInt(Math.Abs(RsltFlgColor)))
                    'Set forecolor black
                    If RsltFlgColor > 0 Then
                        e.Appearance.ForeColor = Color.Black
                    Else
                        e.Appearance.ForeColor = Color.White
                    End If
                End If
            End If
        End If
    End Sub

    ''' <summary>
    ''' This sub sets row background color base on UsgBackground value 
    ''' </summary>
    ''' <param name="aRow"></param>
    ''' <remarks></remarks>
    Public Overridable Sub SetBackgroudColor(ByVal aRow As DataRow, e As RowStyleEventArgs)
        If aRow IsNot Nothing AndAlso Not IsDBNull(aRow("UsgBackground")) Then
            If CType(aRow("UsgBackground"), Decimal) = 0 Then
                e.Appearance.BackColor = ColorTranslator.FromOle(UsageBackgroundEmpty)
            Else
                e.Appearance.BackColor = ColorTranslator.FromOle(CInt(Math.Abs(CType(aRow("UsgBackground"), Decimal))))
            End If

        End If
    End Sub

    Public Overridable Sub SetComment(ByRef aRow As DataRow, e As RowCellStyleEventArgs)
        Dim SpecValueDescr As String = String.Empty

        If Not IsDBNull(aRow("ResultValidationID_FK")) Then
            Dim resultValidationID_FK As Guid = CType(aRow("ResultValidationID_FK"), Guid)
            If e.Column.FieldName = "Comment" AndAlso resultValidationID_FK = IdRepository.APP_VALIDATE_RESULT_CMT Then
                If Not String.IsNullOrEmpty(aRow("Comment").ToString) Then
                    Dim str() As String = aRow("Comment").ToString.Split(","c)
                    Dim aGuid As Guid
                    Dim strGuid As String = str(0)
                    'strGuid = strGuid.Remove(0)
                    'strGuid = strGuid.Remove(strGuid.Length - 1)
                    strGuid = Mid(strGuid, 2, Len(strGuid) - 2)

                    Dim result As Boolean = Guid.TryParse(strGuid, aGuid)

                    If result Then
                        Dim aQueryName As String = "LOV_SpecificationValues"
                        Dim mqEntries As MetaQuery = metaQuery.GetMetaQueryByName(aQueryName)


                        mqEntries.SQLWhere = String.Format("SpecValueID in ({0})", aRow("Comment").ToString)
                        mqEntries.FillResultQuery()

                        For Each row As DataRow In mqEntries.ResultQuery.Rows

                            If Not String.IsNullOrEmpty(SpecValueDescr) Then
                                SpecValueDescr = SpecValueDescr + ", "
                            End If

                            If AppManager.ApplicationOption.DescriptionColumnIndex = 2 Then
                                SpecValueDescr = SpecValueDescr + row("SpecValueDescr_ALT").ToString
                            Else
                                SpecValueDescr = SpecValueDescr + row("SpecValueDescr_PRM").ToString
                            End If
                        Next
                        'e.Column.View.EditingValue = aRow("Comment").ToString
                        'e.Column.View.SetFocusedRowCellValue(e.Column, SpecValueDescr)
                        'e.Column.View.SetRowCellValue(e.RowHandle, e.Column, SpecValueDescr)
                        'aRow("Comment") = SpecValueDescr
                    End If
                End If
            End If
        End If
    End Sub

    Public Overridable Sub SampleDetail_ProcessCurrentMasterRecord(ByVal sender As Object, e As Views.Base.ValidateRowEventArgs)
        Dim aView As GridView = DirectCast(sender, GridView)
        Dim aRow As System.Data.DataRow = aView.GetDataRow(e.RowHandle)

        If e.RowHandle >= 0 Then
            ProcessResult(aRow)
        End If

    End Sub

    ''' <summary>
    ''' This sub sets RsltFlgColor, Valid and WipStat based on current Test Result
    ''' </summary>
    ''' <param name="aRow"></param>
    ''' <remarks></remarks>
    Public Overridable Sub ProcessResult(ByVal aRow As DataRow)
        If aRow IsNot Nothing Then
            '
            If Not IsDBNull(aRow("ResultValidationID_FK")) Then
                Dim resultValidationID_FK As Guid = CType(aRow("ResultValidationID_FK"), Guid)
                '
                If resultValidationID_FK = IdRepository.APP_VALIDATE_RESULT_RES Then
                    'Colonne Result
                    ValidateColumnResult(aRow)
                ElseIf resultValidationID_FK = IdRepository.APP_VALIDATE_RESULT_VAL Then
                    'Colonne Valid
                    ValidateColumnValid(aRow)
                ElseIf resultValidationID_FK = IdRepository.APP_VALIDATE_RESULT_CMT Then
                    'Colonne Comment
                    ValidateColumnComment(aRow)
                End If

            End If
        End If
    End Sub

    Public Overridable Sub ValidateColumnResult(ByVal aRow As DataRow)

        If IsNumeric(aRow("Result")) Then
            Dim result As Single? = CType(aRow("Result"), Single?)
            Dim min As Decimal?
            Dim max As Decimal?

            aRow("LUpd_DT") = Date.Now()
            aRow("LUpd_UId") = AppManager.UserName

            If (String.IsNullOrEmpty(aRow("Minimum").ToString())) Then
                min = Nothing
            Else
                min = CType(aRow("Minimum"), Decimal?)
            End If

            If (String.IsNullOrEmpty(aRow("Maximum").ToString())) Then
                max = Nothing
            Else
                max = CType(aRow("Maximum"), Decimal?)
            End If


            If max.HasValue AndAlso max < result Then
                aRow("RsltFlgColor") = ResultColor.GreaterThanRejection
                aRow("Valid") = 0
                aRow("WipStatID_FK") = IdRepository.SAMPLE_DETAIL_WIPSTATUS_V
                aRow("WIPStat") = "V"
            ElseIf min.HasValue AndAlso result < min Then
                aRow("RsltFlgColor") = ResultColor.LowerThanRejection
                aRow("Valid") = 0
                aRow("WipStatID_FK") = IdRepository.SAMPLE_DETAIL_WIPSTATUS_V
                aRow("WIPStat") = "V"
            ElseIf max.HasValue And min.HasValue Then
                aRow("RsltFlgColor") = ResultColor.ValidEqual
                aRow("Valid") = 1
                aRow("WipStatID_FK") = IdRepository.SAMPLE_DETAIL_WIPSTATUS_C
                aRow("WIPStat") = "C"
            Else
                aRow("RsltFlgColor") = UsageBackgroundEmpty
                aRow("Valid") = 0
                aRow("WipStatID_FK") = IdRepository.SAMPLE_DETAIL_WIPSTATUS_W
                aRow("WIPStat") = "W"
            End If

        Else
            aRow("RsltFlgColor") = UsageBackgroundEmpty
            aRow("Valid") = 0
            aRow("WipStatID_FK") = IdRepository.SAMPLE_DETAIL_WIPSTATUS_W
            aRow("WIPStat") = "W"

        End If

    End Sub

    Public Overridable Sub ValidateColumnValid(ByVal aRow As DataRow)
        If aRow IsNot Nothing Then
            If CBool(aRow("Valid")) Then
                aRow("Valid") = 1
                aRow("WipStatID_FK") = IdRepository.SAMPLE_DETAIL_WIPSTATUS_C
                aRow("WIPStat") = "C"
            Else
                aRow("Valid") = 0
                aRow("WipStatID_FK") = IdRepository.SAMPLE_DETAIL_WIPSTATUS_W
                aRow("WIPStat") = "W"
            End If
        End If
    End Sub

    Public Overridable Sub ValidateColumnComment(ByVal aRow As DataRow)
        If aRow IsNot Nothing Then
            If Not String.IsNullOrEmpty(aRow("Comment").ToString) Then
                aRow("Valid") = 1
                aRow("WipStatID_FK") = IdRepository.SAMPLE_DETAIL_WIPSTATUS_C
                aRow("WIPStat") = "C"
            Else
                aRow("Valid") = 0
                aRow("WipStatID_FK") = IdRepository.SAMPLE_DETAIL_WIPSTATUS_W
                aRow("WIPStat") = "W"
            End If
        End If
    End Sub

    Public Overridable Sub PrintResult(ByVal sender As System.Object, ByVal e As EventArgs)
        Dim mnuItem As DXMenuItem = CType(sender, DXMenuItem)
        Dim queryName As String = "QualitySheetReport"
        Dim reportName As String = "F9Print"


        If mnuItem IsNot Nothing Then
            Dim aRow As DataRow = CType(mnuItem.Tag, DataRow)

            'Dim LotCD As String = CStr(IIf(IsDBNull(aRow("LotCD")), String.Empty, aRow("LotCD").ToString()))
            'Dim LotRev As Integer = CInt(IIf(IsDBNull(aRow("LotRev")), String.Empty, aRow("LotRev").ToString()))
            'Dim OperationCD As String = CStr(IIf(IsDBNull(aRow("OperationCD")), String.Empty, aRow("OperationCD").ToString()))

            Dim QAQCInspLotID_FK As String = CStr(IIf(IsDBNull(aRow("QAQCInspLotID_FK")), String.Empty, aRow("QAQCInspLotID_FK").ToString()))

            Using mquery As MetaQuery = metaQuery.GetMetaQueryByName("QualitySheetReport")
                If mquery IsNot Nothing Then
                    Using report As DevExpress.XtraReports.UI.XtraReport = SCIEF.ActiveFramework.CommonExt.RptNotification.GetReportFromDB(reportName)
                        If report IsNot Nothing Then

                            If Not String.IsNullOrEmpty(mquery.SQLWhere) Then
                                mquery.SQLWhere = mquery.SQLWhere + "AND "
                            End If
                            mquery.SQLWhere = mquery.SQLWhere + String.Format("i.QAQCInspLotID_FK = '{0}'", QAQCInspLotID_FK)
                            'mquery.SQLWhere = mquery.SQLWhere + String.Format(" AND LotSeq = '{0}' AND LotRev = CONVERT(VARCHAR(2), {1}) AND OperationId = (SELECT OperationId FROM Operation WHERE OperationCd = '{2}')", LotCD, LotRev, OperationCD)

                            mquery.FillResultQuery()
                            report.DataSource = mquery.ResultQuery
                            report.ShowPreviewDialog()

                            'Dim aFrm As Form = New ReportPrintForm() With {.Text = "Print Invoice", .RptPrintingSystem = report.PrintingSystem}
                            'aFrm.Show()
                        Else
                            Console.WriteLine(String.Format("{0}, Not Found in Report Definition. Notification abord", reportName))
                        End If
                    End Using
                Else
                    Console.WriteLine(String.Format("{0}, Not Found in MetaCommand. Notification abord", queryName))
                End If
            End Using
        End If


    End Sub

    Public Overridable Sub SetResultValidation(ByVal aRow As DataRow, ByVal aView As GridView)

        If Not IsDBNull(aRow("ResultValidationID_FK")) Then
            Dim resultValidationID_FK As Guid = CType(aRow("ResultValidationID_FK"), Guid)

            If resultValidationID_FK = IdRepository.APP_VALIDATE_RESULT_RES Then
                'Colonne Result
                'aView.Columns("Result").OptionsColumn.AllowEdit = True
                aView.Columns("Valid").OptionsColumn.AllowEdit = False
                'aView.Columns("Comment").OptionsColumn.AllowEdit = False
            ElseIf resultValidationID_FK = IdRepository.APP_VALIDATE_RESULT_VAL Then
                'Colonne Valid
                aView.Columns("Valid").OptionsColumn.AllowEdit = True
                'aView.Columns("Result").OptionsColumn.AllowEdit = False
                'aView.Columns("Comment").OptionsColumn.AllowEdit = False
            ElseIf resultValidationID_FK = IdRepository.APP_VALIDATE_RESULT_CMT Then
                'Colonne Comment
                'aView.Columns("Comment").OptionsColumn.AllowEdit = True
                'aView.Columns("Result").OptionsColumn.AllowEdit = False
                aView.Columns("Valid").OptionsColumn.AllowEdit = False

            End If
        End If



    End Sub


    Public Overridable Sub MasterCustomRowCellEditForEditing(ByVal sender As Object, ByVal e As CustomRowCellEditEventArgs)
        Dim aDetailview As GridView = DirectCast(sender, GridView)
        Dim aRow As DataRow = aDetailview.GetFocusedDataRow()

        If aRow IsNot Nothing Then


            If Not IsDBNull(aRow("ResultValidationID_FK")) Then
                Dim resultValidationID_FK As Guid = CType(aRow("ResultValidationID_FK"), Guid)

                If e.Column.FieldName = "Comment" AndAlso resultValidationID_FK = IdRepository.APP_VALIDATE_RESULT_CMT Then
                    Dim aEdit As RepositoryItemGridLookUpEdit
                    Dim SpecID As Guid
                    Dim sqlWhere As String

                    If aRow IsNot Nothing AndAlso Not IsDBNull(aRow("Specification")) Then
                        SpecID = If(IsDBNull(aRow), Guid.Empty, CType(aRow("Specification"), Guid))
                    Else
                        SpecID = Guid.Empty
                    End If

                    sqlWhere = String.Format("SpecID_FK = '{0}'", SpecID)
                    aEdit = LOVBuilder("LOV_SpecificationValues", sqlWhere, Nothing, Nothing)
                    aEdit.Name = "LOV_SpecificationValues"
                    aEdit.View.OptionsSelection.MultiSelect = True
                    aEdit.View.OptionsSelection.MultiSelectMode = GridMultiSelectMode.RowSelect
                    aDetailview.GridControl.RepositoryItems.Add(aEdit)
                    e.RepositoryItem = aEdit


                    AddHandler aEdit.EditValueChanged, AddressOf Comment_EditValueChanged
                End If
            End If


        End If

    End Sub

    Public Overridable Sub Comment_EditValueChanged(sender As Object, e As System.EventArgs)
        Dim lovSpecValue As GridLookUpEdit = DirectCast(sender, GridLookUpEdit)
        Dim listOfSelectedIndex() As Integer = lovSpecValue.Properties.View.GetSelectedRows
        Dim strSelectedGuid As String = String.Empty

        For Each i As Integer In listOfSelectedIndex
            If String.IsNullOrEmpty(strSelectedGuid) Then
                strSelectedGuid = "'" + lovSpecValue.Properties.View.GetRowCellValue(i, "SpecValueID").ToString + "'"
            Else
                strSelectedGuid = strSelectedGuid + ", '" + lovSpecValue.Properties.View.GetRowCellValue(i, "SpecValueID").ToString + "'"
            End If
        Next

        Dim aGridControl As GridControl = lovSpecValue.Parent
        Dim aGridView As GridView = aGridControl.FocusedView
        Dim aDatRow As DataRow = aGridView.GetFocusedDataRow()
        aDatRow("Comment") = strSelectedGuid
        aGridControl.RepositoryItems("LOV_SpecificationValues").CancelUpdate()
        'aGridControl.RepositoryItems.Remove(aGridControl.RepositoryItems("LOV_SpecificationValues"))
    End Sub

    ' ''' <summary>
    ' ''' This Sub will scope the ItemMasterSpecification LOV, depending on the parent row column ItemMasterRevID_FK
    ' ''' </summary>
    ' ''' <remarks></remarks>
    'Public Overridable Sub SampleDetail_ShownDetailEditor(sender As Object, e As System.EventArgs)
    '    Dim detailView As GridView = DirectCast(sender, GridView)
    '    'Dim aRow As System.Data.DataRow = detailView.GetFocusedDataRow()

    '    'If aRow IsNot Nothing AndAlso aRow.Table.TableName.Equals("SampleDetail") Then

    '    'End If

    '    If detailView.FocusedColumn.FieldName = "ItemMasterSpecID_FK" Then
    '        Dim parentView As GridView = CType(detailView.ParentView, GridView)
    '        Dim SampleHeaderRow As DataRow = parentView.GetFocusedDataRow()

    '        If TypeOf detailView.ActiveEditor Is GridLookUpEdit Then
    '            IMRevision_LookupEdit = CType(detailView.ActiveEditor, GridLookUpEdit)

    '            Dim ItemMasterRevID As Guid = If(IsDBNull(SampleHeaderRow("ItemMasterRevID_FK")), Guid.Empty, CType(SampleHeaderRow("ItemMasterRevID_FK"), Guid))

    '            LotSerialNo = SampleHeaderRow("LotSerialNo").ToString()
    '            'QAQCInspLotID_FK = CType(parentRow("QAQCInspLotID"), Guid)

    '            If detailView.FocusedColumn.FieldName = "ItemMasterSpecID_FK" Then
    '                IMRevision_LookupEdit.Properties.View.ActiveFilterString = String.Format("ItemMasterRevID = '{0}'", ItemMasterRevID)
    '                IMRevision_LookupEdit.Properties.View.OptionsView.ShowFilterPanelMode = Views.Base.ShowFilterPanelMode.Never
    '            End If

    '        End If
    '    ElseIf detailView.FocusedColumn.FieldName = "SpecificationTestRevId_FK" Then
    '        Dim SampleDetailRow As DataRow = detailView.GetFocusedDataRow()
    '        Dim SpecificationID As Guid
    '        Dim SpecRevision As Integer

    '        If TypeOf detailView.ActiveEditor Is GridLookUpEdit Then
    '            Dim edit As GridLookUpEdit = CType(detailView.ActiveEditor, GridLookUpEdit)
    '            edit.Properties.View.ActiveFilterEnabled = False


    '            If SampleDetailRow Is Nothing Then
    '                SpecificationID = Guid.Empty
    '            Else
    '                SpecificationID = If(IsDBNull(SampleDetailRow("SpecID_FK")), Guid.Empty, CType(SampleDetailRow("SpecID_FK"), Guid))
    '                SpecRevision = If(IsDBNull(SampleDetailRow("MaxSpecRevision")), 0, CInt(SampleDetailRow("MaxSpecRevision")))
    '            End If

    '            If Not detailView.FocusedRowHandle.Equals(GridControl.AutoFilterRowHandle) Then
    '                edit.Properties.View.ActiveFilterString = String.Format("IsActivated = 1 and RevisionNumber = {0} and SpecificationId_FK = '{1}' ", SpecRevision, SpecificationID.ToString)
    '                edit.Properties.View.OptionsView.ShowFilterPanelMode = Views.Base.ShowFilterPanelMode.Never
    '            End If
    '        End If

    '    End If
    'End Sub

    ' ''' <summary>
    ' ''' This sub assign values to the current new row. Values are coming from the selected row of the lookupEdit.
    ' ''' </summary>
    ' ''' <remarks></remarks>
    'Public Overridable Sub IMRevision_LookupEdit_CloseUp(sender As Object, e As DevExpress.XtraEditors.Controls.CloseUpEventArgs) Handles IMRevision_LookupEdit.CloseUp
    '    Dim alookup As GridLookUpEdit = DirectCast(sender, GridLookUpEdit)

    '    If alookup.Properties.ValueMember = "ItemMasterSpecID" Then
    '        IMRevision_LookupView = alookup.Properties.View
    '    End If
    'End Sub

    'Public Overridable Sub SampleDetail_DetailRowCellStyle(sender As Object, e As RowCellStyleEventArgs)
    '    Dim aView As GridView = DirectCast(sender, GridView)
    '    Dim aRow As System.Data.DataRow = aView.GetDataRow(e.RowHandle)

    '    If aRow IsNot Nothing AndAlso aRow.Table.TableName.Equals("SampleDetail") Then
    '        SetResultBackcolorForecolor(aRow, e)

    '        'If e.RowHandle >= 0 Then
    '        '    InitResultValidation(e, aRow)
    '        'End If
    '    End If
    'End Sub

    'Public Overridable Sub SampleDetail_DetailRowStyle(ByVal sender As Object, ByVal e As RowStyleEventArgs)
    '    Dim aView As GridView = DirectCast(sender, GridView)
    '    Dim aRow As System.Data.DataRow = aView.GetDataRow(e.RowHandle)

    '    If aRow IsNot Nothing AndAlso aRow.Table.TableName.Equals("SampleDetail") Then
    '        SetBackgroudColor(aRow, e)
    '    End If

    'End Sub

    'Public Overridable Sub SampleDetail_ProcessCurrentDetailRecord(ByVal sender As Object, e As Views.Base.ValidateRowEventArgs, ByVal index As Integer)
    '    Dim aView As GridView = DirectCast(sender, GridView)
    '    Dim aRow As System.Data.DataRow = aView.GetDataRow(e.RowHandle)


    '    If aRow IsNot Nothing AndAlso aRow.Table.TableName.Equals("SampleDetail") Then

    '        If e.RowHandle >= 0 Then
    '            ProcessResult(aRow)
    '        Else
    '            If (IMRevision_LookupView IsNot Nothing) Then
    '                aRow("LotSerialNo") = LotSerialNo
    '                aRow("RepetNmbr") = IMRevision_LookupView.GetRowCellValue(IMRevision_LookupView.FocusedRowHandle, "Repetition")
    '                aRow("Target") = IMRevision_LookupView.GetRowCellValue(IMRevision_LookupView.FocusedRowHandle, "Target")
    '                aRow("Minimum") = IMRevision_LookupView.GetRowCellValue(IMRevision_LookupView.FocusedRowHandle, "Minimum")
    '                aRow("Maximum") = IMRevision_LookupView.GetRowCellValue(IMRevision_LookupView.FocusedRowHandle, "Maximum")
    '                aRow("SpecDetDescrFr") = IMRevision_LookupView.GetRowCellValue(IMRevision_LookupView.FocusedRowHandle, "SpecDescr_ALT")
    '                aRow("SpecDetDescrEng") = IMRevision_LookupView.GetRowCellValue(IMRevision_LookupView.FocusedRowHandle, "SpecDescr_PRM")
    '                aRow("SpecID_FK") = IMRevision_LookupView.GetRowCellValue(IMRevision_LookupView.FocusedRowHandle, "SpecID")
    '                aRow("NumBinSub") = IMRevision_LookupView.GetRowCellValue(IMRevision_LookupView.FocusedRowHandle, "NumBinSub")
    '                aRow("SOP") = IMRevision_LookupView.GetRowCellValue(IMRevision_LookupView.FocusedRowHandle, "SOP")
    '                aRow("Method") = IMRevision_LookupView.GetRowCellValue(IMRevision_LookupView.FocusedRowHandle, "Method")
    '                aRow("Dt_Utilisation") = Date.Today
    '                aRow("Tm_Utilisation") = Date.Today
    '                aRow("UnitId_FK") = IMRevision_LookupView.GetRowCellValue(IMRevision_LookupView.FocusedRowHandle, "UnitID_FK")
    '                aRow("TNTC") = 0
    '                aRow("Valid") = 0
    '                aRow("SampleNo") = LotSerialNo
    '                aRow("CompulsoryRep") = IMRevision_LookupView.GetRowCellValue(IMRevision_LookupView.FocusedRowHandle, "CompulsaryRep")
    '                aRow("UsgBackground") = IMRevision_LookupView.GetRowCellValue(IMRevision_LookupView.FocusedRowHandle, "BackgroundColor")
    '                aRow("WipStat") = "W"
    '                aRow("QAStat") = "O"
    '                aRow("Reject") = 0
    '                aRow("ResultDisplay") = 0
    '                aRow("WipStatID_FK") = IdRepository.SAMPLE_DETAIL_WIPSTATUS_W
    '                aRow("QAStatID_FK") = IdRepository.SAMPLE_DETAIL_QASTATUS_O
    '                aRow("Crtd_DT") = Date.Today
    '                aRow("Crtd_UId") = AppManager.UserName
    '                IMRevision_LookupView = Nothing
    '            End If
    '        End If
    '    End If


    'End Sub

    'Public Overridable Sub SampleDetail_DetailRowCellClick(ByVal sender As Object, ByVal e As RowCellClickEventArgs)
    '    'OUTSANDINGISSUE: To be implement WHEN Result will not be only the Result column (could be Comment, Valid)

    '    'Dim aView As GridView = DirectCast(sender, GridView)
    '    'Dim aRow As System.Data.DataRow = aView.GetDataRow(e.RowHandle)

    '    'If e.RowHandle >= 0 Then
    '    '    If e.Column.Name.Contains("Comment") Then
    '    '        InitResultValidation(e, aRow)
    '    '    End If
    '    'End If
    'End Sub

    'Public Overridable Sub InitResultValidation(ByVal e As RowCellStyleEventArgs, ByVal aRow As DataRow)

    '    If e.Column.Name.Contains("Comment") Then
    '        If e.Column.ColumnEdit Is Nothing And CType(aRow("ResultValidationID_FK"), Guid) = IdRepository.APP_VALIDATE_RESULT_CMT Then
    '            Dim aQueryName As String = "LOV_SpecificationValues"
    '            Dim mqEntries As MetaQuery = MetaQuery.GetMetaQueryByName(aQueryName)
    '            mqEntries.SQLWhere = String.Format("SpecID_FK = '{0}'", aRow("SpecID_FK").ToString)
    '            mqEntries.FillResultQuery()

    '            Dim aLOV As RepositoryItemGridLookUpEdit = New RepositoryItemGridLookUpEdit() With {.DataSource = mqEntries.ResultQuery, .DisplayMember = mqEntries.ResultQuery.Columns(CommonExt.Base.AppManager.ApplicationOption.DescriptionColumnIndex).ToString, .ValueMember = "SpecValueDescr_ALT", .PopupFormSize = New Size(800, 300), .NullText = "(none)"}
    '            aLOV.View.HorzScrollVisibility = Views.Base.ScrollVisibility.Always
    '            aLOV.View.OptionsView.ColumnAutoWidth = False
    '            aLOV.View.OptionsView.ShowAutoFilterRow = True
    '            aLOV.View.OptionsBehavior.ReadOnly = True

    '            e.Column.ColumnEdit = aLOV
    '            e.Column.ColumnEditName = aQueryName
    '        End If
    '    ElseIf e.Column.Name.Contains("Comment") Then
    '        If CType(aRow("ResultValidationID_FK"), Guid) = IdRepository.APP_VALIDATE_RESULT_VAL Then



    '        End If
    '    End If


    'End Sub

    'Public Overridable Sub CheckDecimalSeparator(ByVal value As Integer)
    '    'If Not IsNumeric(value) Then
    '    '    If IsNumeric(Replace(column.Value, CST_NumericFormat_Comma, CST_NumericFormat_Dot)) Then
    '    '        column.Value = Replace(column.Value, CST_NumericFormat_Comma, CST_NumericFormat_Dot)
    '    '    ElseIf IsNumeric(Replace(column.Value, CST_NumericFormat_Dot, CST_NumericFormat_Comma)) Then
    '    '        column.Value = Replace(column.Value, CST_NumericFormat_Dot, CST_NumericFormat_Comma)
    '    '        'End If
    '    '    End If
    '    'End If
    'End Sub




    ''
    ''
    '' OutStandingIssues: A faire en Helper - aleblanc 2011-10-26
    ''
    ''
    Public formatType As DevExpress.Utils.FormatType
    ''' <summary>
    ''' use to Build a LOV for our GRID
    ''' </summary>
    ''' <param name="queryName"></param>
    ''' <param name="sqlWhere"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function LOVBuilder(ByVal queryName As String, ByVal sqlWhere As String, ByVal sqlFrom As String, ByVal filter As String) As RepositoryItemGridLookUpEdit
        Dim aEdit As RepositoryItemGridLookUpEdit
        Dim colVisible As Boolean
        Dim hideCol As Boolean
        Dim colname As String
        Dim Column As DevExpress.XtraGrid.Columns.GridColumn
        Dim view As Views.Base.ColumnView

        Using mq As MetaQuery = metaQuery.GetMetaQueryByName(queryName)
            If Not String.IsNullOrWhiteSpace(sqlWhere) Then
                mq.SQLWhere = sqlWhere
            End If
            '

            'ICI Le DataField filter appliquer quand on a la securité
            If Not String.IsNullOrWhiteSpace(sqlFrom) Then
                mq.SQLFrom = String.Concat(mq.SQLFrom, sqlFrom)
            End If

            If Not String.IsNullOrWhiteSpace(filter) Then
                mq.SQLWhere = String.Concat(mq.SQLWhere, filter)
            End If
            '
            mq.FillResultQuery()
            aEdit = New RepositoryItemGridLookUpEdit() With {.DataSource = mq.ResultQuery, .DisplayMember = mq.ResultQuery.Columns(CommonExt.Base.AppManager.ApplicationOption.DescriptionColumnIndex).ToString, .ValueMember = mq.GUIDField, .PopupFormSize = New Size(800, 300), .NullText = "(none)"}
            aEdit.View.HorzScrollVisibility = Views.Base.ScrollVisibility.Always
            aEdit.View.OptionsView.ColumnAutoWidth = False
            aEdit.View.OptionsView.ShowAutoFilterRow = True
            aEdit.View.OptionsBehavior.ReadOnly = True
            view = aEdit.View
            view.Columns.Clear()
            For Each row As DataRow In mq.MetaColumns.Rows
                colname = row("ColumnName").ToString
                hideCol = False
                If AppManager.ApplicationOption.DescriptionColumnIndex = 2 Then
                    If colname.EndsWith("_ALT") Then
                        hideCol = True
                    End If
                Else
                    If colname.EndsWith("_PRM") Then
                        hideCol = True
                    End If
                End If
                If hideCol = False Then
                    colVisible = CBool(IIf(CInt(row("pVisible")) = 0, False, True))
                    Column = view.Columns.AddField(colname)
                    Column.VisibleIndex = CInt(row("pOrder"))
                    Column.Caption = row("pCaption").ToString
                    Column.Visible = colVisible
                    Column.Width = CInt(row("pWidth"))
                    Column.ToolTip = row("pToolTip").ToString

                    formatType = GetFormatType(row)
                    '
                    Column.DisplayFormat.FormatType = formatType
                    Column.DisplayFormat.FormatString = row("pNumberFormat").ToString
                End If
            Next
            aEdit.DataSource = mq.ResultQuery
            Return aEdit
        End Using
    End Function

    Public Function GetFormatType(ByVal arow As DataRow) As DevExpress.Utils.FormatType
        If (Not String.IsNullOrEmpty(arow("pNumberFormatID_FK").ToString)) Then
            Select Case CType(arow("pNumberFormatID_FK"), Guid)

                Case CommonExt.Base.IdRepository.META_NUMBERFORMAT_CURRENCY, CommonExt.Base.IdRepository.META_NUMBERFORMAT_GENERALNUMBER, CommonExt.Base.IdRepository.META_NUMBERFORMAT_PERCENT, CommonExt.Base.IdRepository.META_NUMBERFORMAT_STANDARD, CommonExt.Base.IdRepository.META_NUMBERFORMAT_SCIENTIFIC
                    Return DevExpress.Utils.FormatType.Numeric

                Case CommonExt.Base.IdRepository.META_NUMBERFORMAT_GENERALDATE, CommonExt.Base.IdRepository.META_NUMBERFORMAT_LONGDATE, CommonExt.Base.IdRepository.META_NUMBERFORMAT_LONGTIME, CommonExt.Base.IdRepository.META_NUMBERFORMAT_MEDIUMDATE, CommonExt.Base.IdRepository.META_NUMBERFORMAT_MEDIUMTIME, CommonExt.Base.IdRepository.META_NUMBERFORMAT_SHORTDATE, CommonExt.Base.IdRepository.META_NUMBERFORMAT_SHORTTIME
                    Return DevExpress.Utils.FormatType.DateTime

                Case CommonExt.Base.IdRepository.META_NUMBERFORMAT_FORMATEXPR
                    Return DevExpress.Utils.FormatType.Custom

                Case Else
                    Return DevExpress.Utils.FormatType.None
            End Select
        Else
            Return DevExpress.Utils.FormatType.None
        End If
    End Function
    ''
    ''
    '' OutStandingIssues: FIN A faire en Helper - aleblanc 2011-10-26
    ''
    ''
End Class
